package pl.enigmatic.reflection;

import java.lang.reflect.Field;


public class PublicPropertyGetter implements Getter {

	private final Field field;
	private final PropertyPath path;

	public PublicPropertyGetter(final Class<?> cls, final String property) throws SecurityException, NoSuchFieldException {
		field = cls.getField(property);
		path = new PropertyPath(property);
	}

	@Override
	public Object get(final Object target) {
		try {
			return field.get(target);
		} catch (final Exception e) {}
		return null;
	}

	@Override
	public Class<?> getType() {
		return field.getType();
	}

	@Override
	public PropertyPath getPath() {
		return path;
	}

}
